//
// Created by 29001 on 2024/11/21.
//

#ifndef HANDWRITTEN_SQLITE_TABLE_H
#define HANDWRITTEN_SQLITE_TABLE_H

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<stdbool.h>
#include <errno.h>
#include <stdint.h>
#include "row.h"

/*
 * we must have the common view that page is the basic and smallest unit to contain the things like table
 * size：table> page> row
 */
const uint32_t PAGE_SIZE = 4096;//4KB as the same as the OS page size
#define TABLE_MAX_PAGES 100 //table's contains maximum page num
const uint32_t ROWS_PER_PAGE = PAGE_SIZE / ROW_SIZE;
const uint32_t TABLE_MAX_ROWS = ROWS_PER_PAGE * TABLE_MAX_PAGES;

/*
 * table structure
 */
typedef struct {
    uint32_t num_rows;
    void *pages[TABLE_MAX_PAGES];//each table's page number
} Table;

Table *new_table();

void free_table(Table *table);

void *row_slot(Table *table, uint32_t row_num);

#endif //HANDWRITTEN_SQLITE_TABLE_H
